﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<!--jqgrid表格组件start-->
<link href="~/Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
<script src="~/Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
<script src="~/Content/scripts/plugins/jqgrid/jqgrid.min.js"></script>
<!--表格组件end-->
<script>
    var keyValue = request('keyValue'), _memberID = "", _enabledMark = "";
    $(function () {
        initControl();
        //GetGrid();
    })
    function initControl() {
        if ("@ViewBag.Mode") $("#Code").attr('disabled', 'disabled');
        //婚姻状况
        $("#MarryInfo").ComboBox({
            data: [{ "key": "1", "value": "未婚" }, { "key": "2", "value": "已婚" }, { "key": "3", "value": "离婚、离异" }, { "key": "4", "value": "丧偶" }],
            height: "200px",
            id: "key",
            text: "value",
            description: "==请选择==",
        });
        $("#State").ComboBox({
            data: [{ "key": 1, "value": "审批中" }, { "key": 2, "value": "有效" }, { "key": 3, "value": "无效" }],
            height: "200px",
            id: "key",
            text: "value",
            description: "==请选择==",
        });
        $("#Sex").ComboBox({
            data: [{ "key": 1, "value": "男" }, { "key": 2, "value": "女" }],
            height: "200px",
            id: "key",
            text: "value",
            description: "==请选择==",
        });
        $("#HasLiveCard").ComboBox({
            data: [{ "key": 1, "value": "是" }, { "key": 0, "value": "否" }],
            height: "200px",
            id: "key",
            text: "value",
            description: "==请选择==",
        });
        if (!!keyValue) {
            $.SetForm({
                url: "../../QualificationManage/Member/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    _memberID = data.MemberID;
                    _enabledMark = data.EnabledMark;
                }
            });
        }
    }
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable1');
        $gridTable.jqGrid({
            url: "../../QualificationManage/Member/GetPStructLsit?MemberId=" + keyValue,
            datatype: "json",
            height: 265,
            autowidth: true,
            colModel: [
               { label: "主键", name: "Id", index: "Id", hidden: true },
               { label: "AccountCode", name: "AccountCode", index: "AccountCode", hidden: true },
               { label: "房产Id", name: "PStructId", index: "PStructId", hidden: true },
               { label: "业户Id", name: "CustomerId", index: "CustomerId", hidden: true },
               { label: "会员Id", name: "MemberId", index: "MemberId", hidden: true },
               { label: "房产名称", name: "PStructName", index: "PStructName", width: 150, align: "center" },
               { label: "业户名称", name: "CustomerName", index: "CustomerName", width: 150, align: "center" },
               {
                   label: "绑定类型", name: "Type", index: "Type", width: 100, align: "center",
                   formatter: function (cellvalue, options, rowObject) {
                       
                       var Type = "@LeSoft.Util.Config.GetValue("SoftType")";
                       if (Type == "1") {
                           return cellvalue == 0 ? "店长" : "店员";
                       }
                       else {
                       } return cellvalue == 0 ? "业主" : "住户";
                   }
               },
               { label: "绑定时间", name: "CreateDate", index: "CreateDate", width: 150, align: "center" },
               {
                   label: "绑定状态", name: "EnabledMark", index: "EnabledMark", width: 150, align: "center",
                   formatter: function (cellvalue, options, rowObject) {
                       return cellvalue == 1 ? "<i class='fa fa-toggle-on'></i>" : "<i class='fa fa-toggle-off'></i>";
                   }
               },
               {
                   label: "是否为默认房产", name: "IsDefault", index: "IsDefault", width: 150, align: "center",
                   formatter: function (cellvalue, options, rowObject) {
                       return cellvalue == 1 ? "<i class='fa fa-toggle-on'></i>" : "<i class='fa fa-toggle-off'></i>";
                   }
               }
            ],
            viewrecords: true,
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            onCellSelect: function (rowid, iCol, cellcontent, e) {
                if (iCol == 10 || iCol == 11) {
                    if (cellcontent == "<i class=\"fa fa-toggle-on\"></i>") $gridTable.setCell(rowid, iCol, "0");
                    else $gridTable.setCell(rowid, iCol, "1");
                }
            }
        });
    }

    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        //postData["MemberID"] = _memberID;
        postData["EnabledMark"] = _enabledMark;
        
        //var objlist = $("#gridTable1").jqGrid("getRowData");
        // var count = 0; DCount = 0;
        //if (objlist.length > 0) {
        //    for (var i = 0; i < objlist.length; i++) {
        //        if (objlist[i].EnabledMark == "<i class=\"fa fa-toggle-off\"></i>") { objlist[i].EnabledMark = 0; }
        //        else if (objlist[i].EnabledMark == "<i class=\"fa fa-toggle-on\"></i>") { objlist[i].EnabledMark = 1; count++ }
        //        if (objlist[i].IsDefault == "<i class=\"fa fa-toggle-off\"></i>") { objlist[i].IsDefault = 0; }
        //        else if (objlist[i].IsDefault == "<i class=\"fa fa-toggle-on\"></i>") { objlist[i].IsDefault = 1; DCount++ }
        //        if (objlist[i].Type == "店长" || objlist[i].Type == "业主") objlist[i].Type = 1;
        //        else if (objlist[i].Type == "店员" || objlist[i].Type == "租户") objlist[i].Type = 0;
        //    }
        //}
        //if (count > 0&&DCount == 0) {
        //        dialogMsg('请配置一个默认房产！', 0);
        //} else if (count > 0&&DCount > 1) {
        //        dialogMsg('最多只能设置一个默认房产！', 0);
        // }
        //else {
        $.SaveForm({
            url: "../../QualificationManage/Member/SaveForm?keyValue=" + keyValue,
            //param: { member: JSON.stringify(postData), pstructlist: JSON.stringify(objlist) },
            param: { member: JSON.stringify(postData) },
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
        // }
    }
</script>

<div style="margin-top: 20px; margin-right: 30px;">
    <table class="form" style="margin-top:20px;">
        <tr>
            <td class="formTitle">会员编号</td>
            <td class="formValue">
                <input id="Code" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
            <td class="formTitle">会员名称</td>
            <td class="formValue">
                <input id="Name" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">手机号码</td>
            <td class="formValue">
                <input id="Phone" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
            <td class="formTitle">固定电话</td>
            <td class="formValue">
                <input id="PhoneNum" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">身份证号</td>
            <td class="formValue">
                <input id="IDCard" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
            <td class="formTitle">邮箱地址</td>
            <td class="formValue">
                <input id="EMail" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">会员状态</td>
            <td class="formValue">
                <div id="State" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>  
            </td>
            <td class="formTitle">性别</td>
            <td class="formValue">
                <div id="Sex" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div> 
            </td>
        </tr>
        <tr>
            <td class="formTitle">民族</td>
            <td class="formValue">
                <input id="Nation" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
            <td class="formTitle">文化程度</td>
            <td class="formValue">
                <input id="Cultural" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">婚姻状况</td>
            <td class="formValue">
                <div id="MarryInfo" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>
            </td>
            <td class="formTitle">户籍地址</td>
            <td class="formValue">
                <input id="HouseholdAddress" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">户籍邮编</td>
            <td class="formValue">
                <input id="HouseholdPostalCode" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
            <td class="formTitle">居住证</td>
            <td class="formValue">
                <input id="LiveCard" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">是否办理本市居住证</td>
            <td class="formValue">
                <div id="HasLiveCard" type="select" class="ui-select" isvalid="yes" checkexpession="IsScript"></div>   
            </td>
            <td class="formTitle">单位名称</td>
            <td class="formValue">
                <input id="CompanyName" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">单位类型</td>
            <td class="formValue">
                <input id="CompanyType" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
            <td class="formTitle">单位电话</td>
            <td class="formValue">
                <input id="CompanyPhone" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">单位地址</td>
            <td class="formValue">
                <input id="CompanyAddress" type="text" class="form-control" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        @*<tr>
                <td colspan="4">
                    <div class="panel-Title" style="border:0px;">绑定房产</div>
                    <table id="gridTable1"></table>
                </td>
            </tr>*@
    </table>
</div>

